package com.ruoyi.web.controller.house;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dataMigration.domain.DoorDataT;
import com.ruoyi.dataMigration.domain.ProjectDataT;
import com.ruoyi.dataMigration.domain.RepairDataT;
import com.ruoyi.dataMigration.service.IDataMigrationTService;
import com.ruoyi.door.domain.HouseDoorT;
import com.ruoyi.door.service.IHouseDoorTService;
import com.ruoyi.info.domain.HouseDoorInfoT;
import com.ruoyi.info.service.IHouseDoorInfoTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 户信息修改Controller
 * 
 * @author tyq
 * @date 2023-04-24
 */
@RestController
@RequestMapping("/house/dataMigration")
public class DataMigrationTController extends BaseController
{
    @Autowired
    private IDataMigrationTService dataMigrationTService;
    @Autowired
    private IHouseDoorTService houseDoorTService;

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importAllData")
    public AjaxResult importAllData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<DoorDataT> util = new ExcelUtil<DoorDataT>(DoorDataT.class);
        List<DoorDataT> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = dataMigrationTService.importUser(userList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @PostMapping("/importDoorTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<DoorDataT> util = new ExcelUtil<DoorDataT>(DoorDataT.class);
        util.importTemplateExcel(response, "用户数据");
    }

    @Log(title = "工程导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importProjectData")
    public AjaxResult importProjectData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<ProjectDataT> util = new ExcelUtil<ProjectDataT>(ProjectDataT.class);
        List<ProjectDataT> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = dataMigrationTService.importProjectUser(userList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @PostMapping("/importProjectTemplate")
    public void importProjectTemplate(HttpServletResponse response)
    {
        ExcelUtil<ProjectDataT> util = new ExcelUtil<ProjectDataT>(ProjectDataT.class);
        util.importTemplateExcel(response, "用户数据");
    }

    @Log(title = "repair导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importRepairData")
    public AjaxResult importRepairData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<RepairDataT> util = new ExcelUtil<RepairDataT>(RepairDataT.class);
        List<RepairDataT> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = dataMigrationTService.importRepairUser(userList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @PostMapping("/importRepairTemplate")
    public void importRepairTemplate(HttpServletResponse response)
    {
        ExcelUtil<RepairDataT> util = new ExcelUtil<RepairDataT>(RepairDataT.class);
        util.importTemplateExcel(response, "用户数据");
    }



}
